home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14487 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: lrz-muenchen.de!news
  2. From: ua302aa@lrz-muenchen.de ()
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Sorting a Binary File
  5. Date: 15 Apr 1996 08:57:53 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4kt32h$m2c@sparcserver.lrz-muenchen.de>
  9. References: <4krpuf$jfp@news1.sympatico.ca>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Gisele Swinson <gisele.swinson@sympatico.ca> writes:
  13.  
  14. >I have declared a structure as follows:
  15.  
  16. >#define max 5
  17.  
  18. >struct customer
  19. >{
  20. >     int seatno;
  21. >     char lastname[15];
  22. >} Customer[max];
  23.  
  24. >I have also initialized the structure as the seat numbers 1-5 and the last 
  25. >name as blank
  26.  
  27. >for(pass=1; pass<max; pass++)
  28. >   for(i = 0; i<max-1; i++)
  29.  
  30. >      if(Customer[i].lastname > Customer[i+1].lastname)
  31.  
  32. This is perfectly valid code, but maybe it's not what you think it is.
  33. "Customer[i].lastname" will _always_ be less that "Customer[i+1].lastname",
  34. so no swapping will ever happen. To compare strings (not just addresses),
  35. use strcmp().
  36.  
  37. Kurt
  38. --
  39. | Kurt Watzka                             Phone : +49-89-2180-6254
  40. | watzka@stat.uni-muenchen.de
  41.  
  42.